<?php
	require '../global.php';
	$db_config = require ROOT.'/tool/database/data.php';
	if(isset($_GET['t'])){
		$table_name = trim($_GET['t']);
		$table = $db_config['tables'][$table_name];
?>
<div class="tabs">
	<ul>
		<li><a href="#base">表基本信息</a></li>
		<li><a href="#field">表字段信息</a></li>
	</ul>
	<div id="base">
		<table class="detail_table" cellspacing="1">
			<tr>
				<th>表名：</th>
				<td><?php echo $table_name?></td>
				<td></td>
			</tr>
			<tr>
				<th>名称：</th>
				<td><?php echo $table['name']?></td>
				<td></td>
			</tr>
			<tr>
				<th>描述：</th>
				<td colspan="2"><?php echo $table['description']?></td>
			</tr>
			<tr>
				<th>模块：</th>
				<td>
				<?php 
				if(array_key_exists('module', $table)){
					foreach ($table['module'] as $m){
						$db_config['module'][$m];
						echo '<a href="javascript: load_table_info(\'module:'. $m .'\')">'.$db_config['module'][$m]['name'].'</a>　';
					}
				}else{
					echo '<a href="javascript:load_table_info(\'module:other\')">'.$db_config['module']['other']['name'].'</a> ';
				}
				?>
				</td>
				<td>可点击查看某模块的所有相关表</td>
			</tr>
			<tr>
				<th>引擎：</th>
				<td><?php echo $table['engine']?></td>
				<td></td>
			</tr>
			<tr>
				<th>记录数：</th>
				<td><?php echo $table['table_rows']?></td>
				<td>SELECT COUNT(*) FROM <?php echo $table_name?></td>
			</tr>
			<tr>
				<th>数据大小：</th>
				<td><?php echo $table['data_length']?></td>
				<td>数据占用的硬盘空间</td>
			</tr>
			<tr>
				<th>索引大小：</th>
				<td><?php echo $table['index_length']?></td>
				<td>索引占用的硬盘空间</td>
			</tr>
			<tr>
				<th>创建时间：</th>
				<td><?php echo $table['create_time']?></td>
				<td></td>
			</tr>
			<tr>
				<th>更新时间：</th>
				<td><?php echo $table['update_time']?></td>
				<td>最新的记录更新的时间</td>
			</tr>
			<tr>
				<th>字符集：</th>
				<td><?php echo $table['collation']?></td>
				<td></td>
			</tr>
			<tr>
				<th>字段数：</th>
				<td><?php echo sizeof($table['fields'])?></td>
				<td>点击“表字段信息”查看明细</td>
			</tr>
		</table>
	</div>
	<div id="field">
		<table class="detail_list_table" cellspacing="1">
			<tr class="title">
				<th>字段</th>
				<th>类型</th>
				<th>默认值</th>
				<th>可空</th>
				<th>键</th>
				<th>备注</th>
			</tr>
			<tr><td colspan="7" id="mt"></td></tr>
			<?php 
			foreach ($table['fields'] as $fn => $f){
			?>
			<tr>
				<td>
				<?php 
					if(!empty($f['name'])){
						echo "[{$f['name']}]";
					}
					echo $fn;
				?>
				</td>
				<td>
					<?php 
						echo $f['type'];
						if($f['length']!=null)
							echo "({$f['length']})";
					?>
				</td>
				<td><?php echo $f['default_value'] ?></td>
				<td><?php echo $f['nullable']?'Y':'' ?></td>
				<td>
					<?php 
						echo $f['pk']?'主键':'';
						if(!empty($f['fk']['type'])){
							switch ($f['fk']['type']){
								case 0:
									echo '逻辑外键';
									break;
								case 1:
									echo '外键';
									break;
							}
							echo $f['fk']['table'].'.'.$f['fk']['field'];
						}
					?>
				</td>
				<td><?php echo $f['description'] ?></td>
			</tr>
			<?php
			}
			?>
		</table>
	</div>
</div>
<?php 
	}else{
		echo '参数错误！';
	}